/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package carreras;

import java.awt.Point;
import java.awt.Rectangle;
import java.text.SimpleDateFormat;
import java.util.regex.Pattern;
import javax.swing.JTable;
import javax.swing.JViewport;

/**
 *
 * @author fanky10
 */
public class Utilidades {
    public static SimpleDateFormat FORMATERO_FECHA_HORA = new SimpleDateFormat("dd/MM/yyyy HH:mm");
    public static SimpleDateFormat FORMATERO_FECHA = new SimpleDateFormat("dd/MM/yyyy");
    public static SimpleDateFormat FORMATERO_HORA = new SimpleDateFormat("HH:mm");
    public static boolean esInteger(String text){
        try{
            Integer.parseInt(text);
            return true;
        }catch(NumberFormatException ex){
            //ignored
            return false;
        }
    }
    
    
    public static boolean esPatente(String text){
        return text.matches("[a-zA-Z]{3}-[0-9]{3}");
//        return text.matches("[a-zA-Z][a-zA-Z][a-zA-Z]-[0-9][0-9][0-9]");
    }
    public static void main(String args[]){
        String text = "jjj-666";
        System.out.println("text: "+text+" es patente?? xD "+esPatente(text));
    }
    public static boolean isKeyFound(String arg,String key){
        return(arg.length()>(key+"=").length() && arg.substring(0, (key+"=").length()).equals(key+"="));
    }
    public static String getValue(String arg,String key){
        return arg.substring((key+"=").length());
    }
    public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) {
        if (!(table.getParent() instanceof JViewport)) {
            return;
        }
        JViewport viewport = (JViewport)table.getParent();

        // This rectangle is relative to the table where the
        // northwest corner of cell (0,0) is always (0,0).
        Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);

        // The location of the viewport relative to the table
        Point pt = viewport.getViewPosition();

        // Translate the cell location so that it is relative
        // to the view, assuming the northwest corner of the
        // view is (0,0)
        rect.setLocation(rect.x-pt.x, rect.y-pt.y);

        // Scroll the area into view
        viewport.scrollRectToVisible(rect);
    }
}
